package com.hotel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.admin.HotelDTO;
import com.forever.common.FileManager;
import com.forever.common.MyUtil;
import com.forever.common.dao.CommonDAO;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class HotelViewAction extends ActionSupport implements Preparable,ModelDriven<HotelDTO>{

	private static final long serialVersionUID = 1L;

	private HotelDTO dto;
	
	@Resource(name="dao")
	private CommonDAO dao;
	
	@Resource(name="myUtil")
	private MyUtil myUtil;
	
	@Resource(name="fileManager")
	private FileManager fileManager;
	
	@Override
	public HotelDTO getModel() {
		return dto;
	}

	@Override
	public void prepare() throws Exception {
		dto = new HotelDTO();		
	}
	
		public String japanList() throws Exception{
				
			HttpServletRequest request = ServletActionContext.getRequest();
			String cp = request.getContextPath();
			
			List<Object>lists = (List<Object>)dao.getListData("hotel.japanListData");
			
			request.setAttribute("lists", lists);
			
			String urllmageFile = cp + "/pds/hotelImage";		
			request.setAttribute("urllmageFile", urllmageFile);
			
			return SUCCESS;
			}
		
		public String chinaList() throws Exception{
			
			HttpServletRequest request = ServletActionContext.getRequest();
			String cp = request.getContextPath();
			
			List<Object>lists = (List<Object>)dao.getListData("hotel.chinaListData");
			
			request.setAttribute("lists", lists);
			
			String urllmageFile = cp + "/pds/hotelImage";		
			request.setAttribute("urllmageFile", urllmageFile);
			
			return SUCCESS;
			}
		
		public String asiaList() throws Exception{
			
			HttpServletRequest request = ServletActionContext.getRequest();
			String cp = request.getContextPath();
			
			List<Object>lists = (List<Object>)dao.getListData("hotel.asiaListData");
			
			request.setAttribute("lists", lists);
			
			String urllmageFile = cp + "/pds/hotelImage";		
			request.setAttribute("urllmageFile", urllmageFile);
			
			return SUCCESS;
			}
		
		public String canadaList() throws Exception{
			
			HttpServletRequest request = ServletActionContext.getRequest();
			String cp = request.getContextPath();
			
			List<Object>lists = (List<Object>)dao.getListData("hotel.canadaListData");
			
			request.setAttribute("lists", lists);
			
			String urllmageFile = cp + "/pds/hotelImage";		
			request.setAttribute("urllmageFile", urllmageFile);
			
			return SUCCESS;
			}
		
		
		public String europeList() throws Exception{
			
			HttpServletRequest request = ServletActionContext.getRequest();
			String cp = request.getContextPath();
			
			List<Object>lists = (List<Object>)dao.getListData("hotel.europeListData");
			
			request.setAttribute("lists", lists);
			
			String urllmageFile = cp + "/pds/hotelImage";		
			request.setAttribute("urllmageFile", urllmageFile);
			
			return SUCCESS;
			}
		
		
		public String oceaniaList() throws Exception{
			
			HttpServletRequest request = ServletActionContext.getRequest();
			String cp = request.getContextPath();
			
			List<Object>lists = (List<Object>)dao.getListData("hotel.oceaniaListData");
			
			request.setAttribute("lists", lists);
			
			String urllmageFile = cp + "/pds/hotelImage";		
			request.setAttribute("urllmageFile", urllmageFile);
			
			return SUCCESS;
			}
		
		public String article() throws Exception{
			
			HttpServletRequest request = ServletActionContext.getRequest();
			String cp = request.getContextPath();
			
			int hotelNum = Integer.parseInt(request.getParameter("hotelNum"));
			
			dto = (HotelDTO)dao.getReadData("hotel.hotel_readData", hotelNum);
			
			if(dto == null)
				return "read-error";
			
			dto.setHotelLocation(dto.getHotelLocation().replaceAll("\r\n", "<br/>"));
			dto.setHotelIntroduce(dto.getHotelIntroduce().replaceAll("\r\n", "<br/>"));
			dto.setTrafficReport(dto.getTrafficReport().replaceAll("\r\n", "<br/>"));
			dto.setFacility(dto.getFacility().replaceAll("\r\n", "<br/>"));
			dto.setRoomFacility(dto.getRoomFacility().replaceAll("\r\n", "<br/>"));
			
			request.setAttribute("dto", dto);
			
			String urllmageFile = cp + "/pds/hotelImage";
			System.out.println("**********"+urllmageFile);
			request.setAttribute("urllmageFile", urllmageFile);
			
			return SUCCESS;
			}
		
		public String seachList() throws Exception{
			
			HttpServletRequest request = ServletActionContext.getRequest();
			String cp = request.getContextPath();
			
			int hotelNationNo = Integer.parseInt(request.getParameter("hotelNationNo"));
			int bedType = Integer.parseInt(request.getParameter("bedType"));
			int inwon = Integer.parseInt(request.getParameter("inwon"));
			String checkin = request.getParameter("checkin");
			String checkout = request.getParameter("checkout");
			System.out.println(checkout);
			
			
			Map<String, Object> hMap = new HashMap<String, Object>();
			
			hMap.put("bedType", bedType);
			hMap.put("hotelNationNo", hotelNationNo);
			hMap.put("inwon", inwon);
			hMap.put("checkin", checkin);
			hMap.put("checkout", checkout);
			
			System.out.println("*****************" + hMap);
			
			List<Object>lists = (List<Object>)dao.getListData("hotel.sheachList",hMap);
			
			request.setAttribute("lists", lists);
			
			String urllmageFile = cp + "/pds/hotelImage";
			System.out.println("**********"+urllmageFile);
			request.setAttribute("urllmageFile", urllmageFile);
			
			
			
			return SUCCESS;
		}
		
		public String reservation() throws Exception{
			
			HttpServletRequest request = ServletActionContext.getRequest();
			String cp = request.getContextPath();
			
			int hotelNum = Integer.parseInt(request.getParameter("hotelNum"));
			
			dto = (HotelDTO)dao.getReadData("hotel.hotel_readData", hotelNum);
			
			if(dto == null)
				return "read-error";
			
			dto.setHotelLocation(dto.getHotelLocation().replaceAll("\r\n", "<br/>"));
			dto.setHotelIntroduce(dto.getHotelIntroduce().replaceAll("\r\n", "<br/>"));
			dto.setTrafficReport(dto.getTrafficReport().replaceAll("\r\n", "<br/>"));
			dto.setFacility(dto.getFacility().replaceAll("\r\n", "<br/>"));
			dto.setRoomFacility(dto.getRoomFacility().replaceAll("\r\n", "<br/>"));
			
			request.setAttribute("dto", dto);
			
			String urllmageFile = cp + "/pds/hotelImage";
			request.setAttribute("urllmageFile", urllmageFile);
			
			
			return SUCCESS;
		}

}
